/**
 * 出发日期
 * @email 626097912@qq.com
 * Created by dength on 2017/04/21
 */
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    Alert
} from 'react-native';
import BaseComponent from '../base/baseComponent';
import Constants from '../base/constants';
import CommonStyles from '../base/commonStyles';
import Calendar from '../components/calendar';
import { getNavigator } from '../route/route';
import store from 'react-native-simple-store';
import moment from 'moment';

let DATE_FORMAT = 'YYYY-MM-DD';
//获取当前时间
const currentTime = moment().format(DATE_FORMAT);

class DepartureDate extends BaseComponent {
    constructor(props) {
        super(props);
        this.state = {
            selectedDate: [currentTime]
        }
    }

    getNavigationBarProps() {
        return {
            title: '出发日期',
            leftButtonImage: require('../images/ic_return.png'),
            hideRightButton: true,
        };
    }

    // onLeftPressed() {
    //     let { selectedDate } = this.state;
    //     getNavigator().push({
    //         name: 'GrabTicket',
    //         selectedDate: selectedDate,
    //     });
    // }

    renderBody() {
        let { pages} = this.props;
        return (
            <View style={styles.container}>
                <Calendar
                    //showDateRange={['2017-04-01', '2017-06-30']}    //显示的日期范围
                    //enableDateRange={['2017-04-26', '2017-05-26',]} //启用日期范围
                    selectedDate={this.state.selectedDate}         //选定的日期
                    //onChange={(value) => { this.setState({ selectedDate: [JSON.stringify(value[0]).replace(/\"/g, "")] }) } }  //获得选择的日期
                    onChange={(value) => {
                        setTimeout(function () {
                            store.update('TrainIndex', {
                                selectedDate: [JSON.stringify(value[0]).replace(/\"/g, "")]
                            }).then(() => {
                                if (pages === 1) {
                                    getNavigator().push({
                                        name: 'RtrainList',
                                    })
                                } else {
                                    getNavigator().push({
                                        name: 'GrabTicket',
                                    })
                                }
                            });
                        }, 1000);
                    } }  //获得选择的日期
                    renderDate={(param = {}) => {
                        const { selected, innerSelected, date, text, disable } = param;
                    } }
                    />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: CommonStyles.colors.background,
    },
});

export default DepartureDate;